<template>
  <div class="app-container">
    <el-card>
      <el-form label-width="auto" :model="searchForm" size="small" inline>
        <el-form-item label="分类">
          <el-select
            clearable
            v-model="searchForm.cateId"
            placeholder="请选择"
          >
          <el-option
            v-for="item in cateList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-refresh" @click="refresh"
            >重置</el-button
          >
          <el-button
            type="primary"
            size="small"
            icon="el-icon-search"
            @click="search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <div class="filter-container">
        <el-button
          type="primary"
          size="small"
          icon="el-icon-plus"
          @click="handleAdd"
          >添加</el-button
        >
      </div>
      <el-table
        style="margin-top: 20px"
        v-loading="listLoading"
        :data="tableData.data"
        border
        size="mini"
      >
        <!-- <el-table-column type="selection" width="55"></el-table-column> -->
        <el-table-column label="序号" width="60" type="index" align="center" />
        <el-table-column label="分类" prop="cateName" align="center" />
        <el-table-column label="条件名称" prop="name" align="center" />
        <el-table-column
          label="一般基本条件"
          prop="threshold"
        ></el-table-column>
        <el-table-column label="优势项" align="center">
          <template slot-scope="scope">
            <span>{{
              scope.row.advantage == 0 ? "无" : scope.row.advantageDesc
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="劣势项" align="center">
          <template slot-scope="scope">
            <span>{{
              scope.row.recessive == 0 ? "无" : scope.row.recessiveDesc
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="排序" prop="sort" align="center" />
        <el-table-column
          prop="updateTime"
          align="center"
          label="更新时间"
        ></el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleEdit( scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleDelete( scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pageRight"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 40]"
        :current-page="searchForm.pageNum"
        :page-size="searchForm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { getEnterpriseList , deleteEnterprise} from "@/api/campanyData";
import { getDictLabel, getDictData } from "@/utils/dict";
export default {
  data() {
    return {
      listLoading: false,
      tableData: {
        data: [],
        total: 0,
      },
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        cateId: "",
      },
      cateList: [],
    };
  },
  async created() {
    this.cateList = await getDictData("enter_info_cate");
    this.getList();
  },
  methods: {
    handleEdit(v) {
      this.$router.push({ path: "/enterpriseReport/addConfig", query: {id: v.id } });
    },
    handleDelete(v) {
      this.$confirm("此操作将删除该企业信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteEnterprise(v.id).then((res) => {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getList();
          })
        })
    },
    handleSizeChange(val) {
      this.searchForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.searchForm.pageNum = val;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      getEnterpriseList(this.searchForm)
        .then((res) => {
          res.data.list.forEach((v) => {
            v.cateName = getDictLabel(v.category, this.cateList);
          });
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.total;
          this.listLoading = false;
        })
        .finally(() => {
          this.listLoading = false;
        });
    },
    search() {
      this.searchForm.pageNum = 1;
      this.getList();
    },
    refresh() {
      this.searchForm = {
        pageNum: 1,
        pageSize: 10,
        cateId: "",
      };
      this.getList();
    },
    handleAdd() {
      this.$router.push({ path: "/enterpriseReport/addConfig" });
    },
  },
};
</script>

<style></style>
